package com.general.framework.mq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * 👉 the broker's disk is full [CL: 0.91 CQ: 0.91 INDEX: 0.91], messages are put to the slave, message store has been shut down, etc.
 * 该报错由于 /store/commitlog文件夹下的日志文件过大造成，df-h 指令查看当前磁盘占用内存情况 rocketmq默认会把剩余磁盘的比率不足85%当做磁盘空间不足处理
 *
 * 解决办法：
 *
 * 1.先删除掉/store/commitlog文件夹下的没用的日志文件
 *
 * 2.编辑/conf/2m-2s-async/broker-a.properties文件，添加 diskMaxUsedSpaceRatio=98 磁盘占用到98%才会报错
 *
 * 注意：这里要根据服务器不同主从节点对应的配置文件修改
 */
@RestController
@RequestMapping("/rocket")
public class RocketMqController {
    @Autowired
    private final MqProducer mqProducer;

    public RocketMqController(MqProducer mqProducer) {
        this.mqProducer = mqProducer;
    }

    @GetMapping("/send")
    public void send(@RequestParam(name = "topic", required = false) String topic, @RequestParam(name = "message") String message) {
        if (!StringUtils.hasText(topic)){
            topic = "my-topic";
        }
        mqProducer.send(topic, message);
    }
}
